#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<list>
#include<cstdlib>
#include<cmath>
#include<sstream>
#include<numeric>
#include<cstdio>
#include<cstring>
#include<stack>
#define PI acos(-1)
#define MP make_pair
#define PB push_back
#define VI vector <int>
#define PII pair <int,int>
#define LL long long
#define SET(v,i) memset(v, i, sizeof(v))
#define FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define FORD(i,a,b) for (int i = (a); i >= (b); i--)
#define FORN(i,a,b) for (int i = (a); i < (b); i++)
#define DOWN(i,a,b) for (int i = (a); i > (b); i--)
#define FIT(it,v) for (typeof(v.begin()) it = v.begin(); it != v.end(); it++)
#define FITD(it,v) for (typeof(v.rbegin()) it = v.rbegin(); it != v.rend(); it++)
using namespace std;
const int MAXN=201;
char a[MAXN],b[MAXN];
int cnt[MAXN];
int main(){
	int b,d;
	while(cin>>b>>d>>a>>c){
		int n=strlen(c);
		memset(cnt,0,sizeof(cnt));
		memset(next,0,sizeof(next));
		for(int i=0;c[i];i++){
			for(int j=0;a[j];j++)if(a[j]==c[(i+cnt[i])%n])cnt[i]++;
			}
		int s=0;
		for(int i=0;i<b;i++)s+=cnt[s%n];
		cout<<s/n/d<<endl;	
		}
    return 0;
    }
